import axios from "axios";
import React, { useState } from "react";
import { useNavigate } from "react-router-dom";

const Index: React.FC = () => {
  const [username, setUsername] = useState("");
  const [password, setPassword] = useState("");
  const navigate = useNavigate()
  const login = async () => {
    const data = {
      username,
      password,
    };
    const resp = await axios.post("/api/login", data);
    localStorage.setItem("role", resp.data.data.role);
    navigate('/home')

  };
  return (
    <div>
      <input
        type="text"
        value={username}
        onChange={(e) => setUsername(e.target.value)}
      />
      <input
        type="text"
        value={password}
        onChange={(e) => setPassword(e.target.value)}
      />
      <button onClick={login}>登录</button>
    </div>
  );
};

export default Index;
